package com.mbc.rmt.dao;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.mbc.common.dao.DAO;
import com.mbc.rmt.entities.CashCollectionRpt;
import com.mbc.rmt.entities.CashPaymentCollectionRpt;
import com.mbc.rmt.entities.CashReceivedCollectionRpt;

public class SpecialReportDAOImpls extends DAO<CashCollectionRpt> implements SpecialReportDAO{

	public SpecialReportDAOImpls(Connection conn) {
		this.conn = conn;
	}

	@Override
	protected CashCollectionRpt readRecord(ResultSet rs) throws SQLException{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ResultSet prepareCashCollectionReport(CashCollectionRpt info)
			throws SQLException {
		// TODO Auto-generated method stub
		ResultSet l_rs;
		String l_query = "dbo.sp_cr_CashCollectionRpt  ?, ?, ?, ?, ?, ?, ?, ?";

		CallableStatement l_pstmt = conn.prepareCall(l_query);
		CashCollectionRptParameter(l_pstmt, info);
		l_rs = l_pstmt.executeQuery();
		return l_rs;
	}
	
	private static void CashCollectionRptParameter(CallableStatement l_pstmt,
			CashCollectionRpt  info) throws SQLException {
		int i = 1;
		l_pstmt.setString(i++, info.getTodate());		
		l_pstmt.setString(i++, info.getFromagentid());
		l_pstmt.setString(i++, info.getToagentid());		
		l_pstmt.setString(i++, info.getFromtypeid());
		l_pstmt.setString(i++, info.getTotypeid());
		l_pstmt.setBoolean(i++, info.getChktype());
		l_pstmt.setString(i++, info.getOrderby());
		l_pstmt.setLong(i++, info.getBranchid());
	}

	@Override
	public ResultSet prepareCashRecrivedCollectionReport(
			CashReceivedCollectionRpt info) throws SQLException {
		// TODO Auto-generated method stub
		ResultSet l_rs;
		String l_query = "dbo.[sp_cr_CashReceivedCollectionRpt]  ?, ?, ?, ?, ?, ?, ?";

		CallableStatement l_pstmt = conn.prepareCall(l_query);
		CashReceivedCollectionRptParameter(l_pstmt, info);
		l_rs = l_pstmt.executeQuery();
		return l_rs;
	}
	
	private static void CashReceivedCollectionRptParameter(CallableStatement l_pstmt,
			CashReceivedCollectionRpt  info) throws SQLException {
		int i = 1;
		l_pstmt.setString(i++, info.getTodate());		
		l_pstmt.setString(i++, info.getFromagentid());
		l_pstmt.setString(i++, info.getToagentid());		
		l_pstmt.setString(i++, info.getFrombranchid());
		l_pstmt.setString(i++, info.getTobranchid());
		l_pstmt.setString(i++, info.getOrderby());
		l_pstmt.setLong(i++, info.getBranchid());
	}

	@Override
	public ResultSet prepareCashPaymentCollectionReport(
			CashPaymentCollectionRpt info) throws SQLException {
		// TODO Auto-generated method stub
		ResultSet l_rs;
		String l_query = "dbo.sp_cr_CashPaymentCollectionRpt ?, ?, ?, ?, ?, ?, ?";

		CallableStatement l_pstmt = conn.prepareCall(l_query);
		CashPaymentCollectionRptParameter(l_pstmt, info);
		l_rs = l_pstmt.executeQuery();
		return l_rs;
	}
	
	private static void CashPaymentCollectionRptParameter(CallableStatement l_pstmt,
			CashPaymentCollectionRpt  info) throws SQLException {
		int i = 1;
		l_pstmt.setString(i++, info.getTodate());
		l_pstmt.setString(i++, info.getFromagentid());
		l_pstmt.setString(i++, info.getToagentid());
		l_pstmt.setString(i++, info.getFrombranchid());
		l_pstmt.setString(i++, info.getTobranchid());
		l_pstmt.setString(i++, info.getOrderby());
		l_pstmt.setLong(i++, info.getBranchid());
	}

}
